home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / unix / c / time < prev    next >
Text File  |  1996-11-09  |  2KB  |  92 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/unix/c/RCS/time,v $
  4.  * $Date: 1996/04/19 21:35:27 $
  5.  * $Revision: 1.1 $
  6.  * $State: Rel $
  7.  * $Author: simon $
  8.  *
  9.  * $Log: time,v $
  10.  * Revision 1.1  1996/04/19 21:35:27  simon
  11.  * Initial revision
  12.  *
  13.  ***************************************************************************/
  14.  
  15. static const char rcs_id[] = "$Id: time,v 1.1 1996/04/19 21:35:27 simon Rel $";
  16.  
  17. #include <time.h>
  18. #include <errno.h>
  19.  
  20. #include <sys/times.h>
  21. #include <sys/os.h>
  22. #include <sys/syslib.h>
  23.  
  24. clock_t
  25. clock (void)
  26. {
  27.   unsigned int b[2];
  28.   unsigned int t1, t2;
  29.   _kernel_oserror *e;
  30.  
  31.   *((char *) b) = 3;
  32.   if (e = os_word (0x0e, b))
  33.     {
  34.       __seterr (e);
  35.       return (-1);
  36.     }
  37.  
  38.   t1 = (b[0]);
  39.   t2 = (b[1] & 0xff);
  40.  
  41.   if (t2 - __time[1])
  42.     {
  43.       errno = ERANGE;
  44.       return ((clock_t) - 1);
  45.     }
  46.  
  47.   return (t1 - __time[0]);
  48. }
  49.  
  50. time_t
  51. time (time_t * t)
  52. {
  53.   unsigned int b[2];
  54.   unsigned int t1, t2, tc;
  55.   _kernel_oserror *e;
  56.  
  57.   *((char *) b) = 3;
  58.   if (e = os_word (0x0e, b))
  59.     {
  60.       __seterr (e);
  61.       return (-1);
  62.     }
  63.  
  64.   t1 = (b[0]);
  65.   t2 = (b[1] & 0xff);
  66.  
  67.   tc = 0x6e996a00U;
  68.   if (t1 < tc)
  69.     t2--;
  70.   t1 -= tc;
  71.   t2 -= 0x33;            /* 00:00:00 Jan. 1 1970 = 0x336e996a00 */
  72.  
  73.   t1 = (t1 / 100) + (t2 * 42949673U);    /* 0x100000000 / 100 = 42949672.96 */
  74.   t1 -= (t2 / 25);        /* compensate for .04 error */
  75.  
  76.   if (t)
  77.     *t = t1;
  78.  
  79.   return (t1);
  80. }
  81.  
  82. clock_t
  83. times (struct tms * tmsp)
  84.  
  85. {
  86.   tmsp->tms_utime = clock ();    /* user time */
  87.   tmsp->tms_stime = 0;        /* system time */
  88.   tmsp->tms_cutime = 0;        /* user time, children */
  89.   tmsp->tms_cstime = 0;        /* system time, children */
  90.   return tmsp->tms_utime;
  91. }
  92.